//
//  APIURLManager.m
//  OCStarterProject
//
//  Created by huaya on 2025/10/2.
//

#import "APIURLManager.h"

@implementation APIURLManager

static NSString *const kEnvironmentKey = @"APIEnvironment";
static NSString *const kDevEnvironment = @"development";
static NSString *const kTestEnvironment = @"test";
static NSString *const kProdEnvironment = @"production";

#pragma mark - Base URLs

+ (NSString *)devBaseURL {
    return @"https://dev.taintale.com";
}

+ (NSString *)testBaseURL {
    return @"https://dev.taintale.com";
}

+ (NSString *)prodBaseURL {
    return @"https://api.taintale.com";
}

+ (NSString *)currentBaseURL {
    // 根据构建模式自动选择环境
    // Debug 模式使用开发环境，Release 模式使用生产环境
#ifdef DEBUG
    NSString *baseURL = [self devBaseURL];
    NSLog(@"🔧 当前构建模式: Debug, 使用开发环境: %@", baseURL);
    return baseURL;
#else
    NSString *baseURL = [self prodBaseURL];
    NSLog(@"🔧 当前构建模式: Release, 使用生产环境: %@", baseURL);
    return baseURL;
#endif
}

#pragma mark - API URLs
+ (NSString *)Feed_Back {
    return [self buildURLWithPath:@"/feedback"];
}
+ (NSString *)Tourists_Login {
    return [self buildURLWithPath:@"/user/device-login"];
}
+ (NSString *)Google_Login {
    return [self buildURLWithPath:@"/google/googleLoginWithAccessToken"];
}

+ (NSString *)Google_Bind {
    return [self buildURLWithPath:@"/google/bindWithAccessToken"];
}

+ (NSString *)Facebook_Login {
    return [self buildURLWithPath:@"/api/auth/social/facebook/login"];
}
+ (NSString *)Facebook_User_Login {
    return [self buildURLWithPath:@"/api/auth/social/facebook/userLogin"];
}

+ (NSString *)Facebook_Bind {
    return [self buildURLWithPath:@"/api/auth/social/facebook/bind"];
}

+ (NSString *)Facebook_Bind_params {
    return [self buildURLWithPath:@"/api/auth/social/facebook/bind/params"];
}
+ (NSString *)queryChannelByColumn {
    return [self buildURLWithPath:@"/works/os-channel/queryChannelByColumn"];
}

+ (NSString *)queryOsWorksByChannel {
    return [self buildURLWithPath:@"/works/os-works/queryOsWorksByChannel"];
}

+ (NSString *)sendEmailValidCode {
    return [self buildURLWithPath:@"/users/os-users/sendEmailValidCode"];
}

+ (NSString *)emailLogin {
    return [self buildURLWithPath:@"/users/os-users/emailLogin"];
}

+ (NSString *)getUserInfo {
    return [self buildURLWithPath:@"/users/os-users/getUserInfo"];
}

+ (NSString *)queryChapterByWorksId {
    return [self buildURLWithPath:@"/works/os-chapter/queryChapterByWorksId"];
}

+ (NSString *)querySSChapterByWorksId {
    return [self buildURLWithPath:@"/works/os-chapter/queryShortByWorksId"];
}

+ (NSString *)systemNoticeList {
    return [self buildURLWithPath:@"/system/notice/list"];
}

+ (NSString *)systemNoticeRightList {
    return [self buildURLWithPath:@"/notifications"];
}

+ (NSString *)systemNoticeLikes {
    return [self buildURLWithPath:@"/notifications/likes"];
}

+ (NSString *)systemNoticeComments {
    return [self buildURLWithPath:@"/notifications/comments"];
}

+ (NSString *)changeUserInfo {
    return [self buildURLWithPath:@"/users/os-users/changeUserInfo"];
}

+ (NSString *)uploadAvatar {
    return [self buildURLWithPath:@"/users/os-users/uploadBase64"];
}

+ (NSString *)getOsGoodsList {
    return [self buildURLWithPath:@"/users/os-goods/getOsGoodsList"];
}

+ (NSString *)userWriteOff {
    return [self buildURLWithPath:@"/users/os-users/write-off"];
}

+ (NSString *)getAliYunOSSConfig {
    return [self buildURLWithPath:@"/oss-file/getStsToken"];
}

+ (NSString *)getPaymentRecords {
    return [self buildURLWithPath:@"/users/os-payment-records"];
}

+ (NSString *)getUserPaid {
    return [self buildURLWithPath:@"/users/os-user-paid"];
}

+ (NSString *)getCategoryListSub {
    return [self buildURLWithPath:@"/category/list-sub"];
}

+ (NSString *)getCategoryQueryOsWorks {
    return [self buildURLWithPath:@"/works/os-works/queryOsWorks"];
}

+ (NSString *)getUsersBuyWorks {
    return [self buildURLWithPath:@"/users/os-user-paid/buyWorks"];
}

+ (NSString *)getBookDetails {
    return [self buildURLWithPath:@"/works/os-works/detail"];
}

+ (NSString *)getBookChaptersList {
    return [self buildURLWithPath:@"/works/os-works/queryChapter"];
}

+ (NSString *)collectBook {
    return [self buildURLWithPath:@"/users/os-library/collect"];
}

+ (NSString *)cancelCollectBook {
    return [self buildURLWithPath:@"/users/os-library/cancel"];
}

+ (NSString *)getCollectList {
    return [self buildURLWithPath:@"/users/os-library"];
}

+ (NSString *)delCollectList {
    return [self buildURLWithPath:@"/users/os-library/cancel"];
}

+ (NSString *)getHistoryList {
    return [self buildURLWithPath:@"/oversea/view"];
}

+ (NSString *)queryOsWorksAll {
    return [self buildURLWithPath:@"/works/os-works/queryOsWorksAll"];
}

+ (NSString *)likeGoods {
    return [self buildURLWithPath:@"/likes"];
}

+ (NSString *)commentGoods {
    return [self buildURLWithPath:@"/comments"];
}

+ (NSString *)replyGoods {
    return [self buildURLWithPath:@"/comments/reply"];
}

+ (NSString *)replyDetailGoods {
    return [self buildURLWithPath:@"/comments/detail"];
}

+ (NSString *)notUnReadCount {
    return [self buildURLWithPath:@"/notifications/un-read-count"];
}

+ (NSString *)cancelPayURL {
    return [self buildURLWithPath:@"/apple/payment/cancelPay"];
}

+ (NSString *)applePrepayURL {
    return [self buildURLWithPath:@"/apple/payment/applePrepay"];
}

+ (NSString *)applePayURL {
    return [self buildURLWithPath:@"/apple/payment/applePay"];
}

+ (NSString *)bookRead {
    return [self buildURLWithPath:@"/works/read"];
}

+ (NSString *)helpConfig {
    return [self buildURLWithPath:@"/help-config"];
}

+ (NSString *)appleLogin {
    return [self buildURLWithPath:@"/apple/login"];
}

+ (NSString *)guestAuthLogin {
    return [self buildURLWithPath:@"/users/os-users/guestAuthLogin"];
}

+ (NSString *)getMyBonusInfo {
    return [self buildURLWithPath:@"/currency/info"];
}

+ (NSString *)getMyBonusList:(NSInteger)status {
    return [self buildURLWithPath:[NSString stringWithFormat:@"/currency/list/%ld", (long)status]];
}

+ (NSString *)getTaskList {
    return [self buildURLWithPath:@"/task/list"];
}

+ (NSString *)Bind_Email {
    return [self buildURLWithPath:@"/api/auth/social/bindEmail/bind"];
}

+ (NSString *)taskSignIn:(NSInteger)taskId {
    return [self buildURLWithPath:[NSString stringWithFormat:@"/task/signIn/%ld", (long)taskId]];
}

+ (NSString *)taskComplete:(NSInteger)taskId {
    return [self buildURLWithPath:[NSString stringWithFormat:@"/task/complete/%ld", (long)taskId]];
}

+ (NSString *)taskReceiveReward:(NSInteger)taskId {
    return [self buildURLWithPath:[NSString stringWithFormat:@"/task/receiveReward/%ld", (long)taskId]];
}
+ (NSString *)systemNoticeWithNoticeId:(NSNumber *)noticeId {
    
    return [self buildURLWithPath:[NSString stringWithFormat:@"/system/notice/%@", noticeId]];
}
+ (NSString *)getLibrary{
    
    return [self buildURLWithPath:@"/users/os-library/getLibrary"];
}

#pragma mark - Utility Methods

+ (NSString *)buildURLWithPath:(NSString *)path {
    NSString *baseURL = [self currentBaseURL];
    return [NSString stringWithFormat:@"%@%@", baseURL, path];
}

+ (void)switchToEnvironment:(NSString *)environment {
    [[NSUserDefaults standardUserDefaults] setObject:environment forKey:kEnvironmentKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)currentEnvironment {
    NSString *environment = [[NSUserDefaults standardUserDefaults] stringForKey:kEnvironmentKey];
    if (!environment) {
        // 默认使用开发环境
        environment = kDevEnvironment;
        [self switchToEnvironment:environment];
    }
    return environment;
}
+ (NSString *)PrivacyURL {
    return @"https://www.taintale.com/privacy";
}
+ (NSString *)AgreementURL {
    return @"https://www.taintale.com/agreement";
}
@end
